package parser

import (
	"01-crawler-project/01/engine"
	"fmt"
	"net/http"
	"regexp"
)

var regex_userinfo_link = regexp.MustCompile(`<a href="(http://album.zhenai.com/u/\d+)" target="_blank">([^<]+[^>])</a>`)

func ParseCityUserInfo(contents [] byte) engine.ParserResult {

	result := engine.ParserResult{}

	userinfo_link := regex_userinfo_link.FindAllStringSubmatch(string(contents), -1)

	result.Requests = make([]engine.Request, len(userinfo_link))

	result.Items = make([] interface{}, len(userinfo_link))

	for k, v := range userinfo_link {

		request, _ := http.NewRequest(http.MethodGet, v[1], nil)

		result.Requests[k] = engine.Request{HttpRequest: request, ParserFunc: ParseProfile}

		result.Items[k] = v[2]

		fmt.Println(k, v)
	}

	return result
}
